package myJs.api

import japgolly.scalajs.react.extra.Ajax
import myJs.myPkg.MyFetch
import upickle.default._
import org.scalajs.macrotaskexecutor.MacrotaskExecutor.Implicits._
import shared.pojo.Data.DataInfo

/**
	*Created by yz on 12/9/2023
	*/object Data {

  val baseUrl = s"${Api.apiUrl}/data"

  def all = {
    val url = s"${baseUrl}/all"
    Ajax("GET", s"${url}").setRequestContentTypeJson
                          .send
                          .asAsyncCallback
                          .map { xhr =>
                            read[List[ujson.Obj]](xhr.responseText)
                          }
  }

  def allRsNumber = {
    val url = s"${baseUrl}/allRsNumber"
    Ajax("GET", s"${url}").setRequestContentTypeJson
                          .send
                          .asAsyncCallback
                          .map { xhr =>
                            read[List[String]](xhr.responseText)
                          }
  }

  def getById(idV: String) = {
    val url = s"${baseUrl}/getById?id=${idV}"
    Ajax("GET", s"${url}").setRequestContentTypeJson
                          .send
                          .asAsyncCallback
                          .map { xhr =>
                            read[DataInfo](xhr.responseText)
                          }
  }

}
